// 获取考试成绩
let score = localStorage.score;
$("#score").text(score + "分");
// 获取本地全部详情数据
let detailData = JSON.parse(localStorage.getItem("detailPageData"));
console.log(detailData);

// 选项数组
let checkBox = ["A", "B", "C", "D", "未选"];

// 错题数量
let errorNum = 0;
//遍历渲染
detailData.forEach((v, index) => {
  // 当前题目正确答案下标
  let answer = v.answer;
  //   当前题目的学生选项下标
  let studentOption = v.studentOption;

  $("#detail-items").append(`
    <div class='exe${index}' style='display:none'>
     <div class="questions">
              <span>${index + 1}.</span>
              <p class="question">${v.topics}</p>
            </div>
            <div class="slectAnswer" data-index='${index}'>
              <div class="item  slectOption${index}" >
                <span class="slect">A</span>
                <span >${v.options[0]}</span>
              </div>
              <div class="item slectOption${index}" >
                <span class="slect">B</span>
                <span >${v.options[1]}</span>
              </div>
              <div class="item slectOption${index}" >
                <span class="slect">C</span>
                <span > ${v.options[2]}</span>
              </div>
              <div class="item slectOption${index}" >
                <span class="slect">D</span>
                <span >${v.options[3]}</span>
              </div>
            </div>
            <div class="footer">
            <h6>考生答案：${
              checkBox[studentOption >= 0 ? studentOption : 4]
            }</h6>
            <h6>正确答案：${checkBox[answer]}</h6>
            <p>解析：${v.analysis}</p>
          </div>
    </div>

`);

  if (answer != studentOption && studentOption != -1) {
    errorNum++;
    $(`.slectOption${index}`).eq(answer).addClass("rightActive");
    $(`.slectOption${index}`).eq(studentOption).addClass("errorActive");
  } else {
    $(`.slectOption${index}`).eq(answer).addClass("rightActive");
  }

  $(`.exe0`).show();
});

let currentPage = 0;
render();
function render() {
  $("#errorNum").text(errorNum);
  $("#currentPage").text(currentPage + 1);
  $("#total").text(detailData.length);
}

// 上一题
$("#preExe").on("click", function () {
  if (currentPage <= 0) return alert("前面没有了");
  currentPage--;
  $(`.exe${currentPage}`).show().siblings().hide();
  $("#currentPage").text(currentPage + 1);

  // console.log(currentPage);
});

// 下一题
$("#nextExe").on("click", function () {
  if (currentPage >= detailData.length - 1) return alert("已经到底了");
  currentPage++;
  $(`.exe${currentPage}`).show().siblings().hide();
  $("#currentPage").text(currentPage + 1);
  // console.log(currentPage);
});
